package 集合框架.kgc.课后作业.M2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Student {

    private static List<Employee> list = new ArrayList();

    static {
        list.add(new Employee(1, "张三", 18, 3000));
        list.add(new Employee(2, "李四", 25, 3500));
        list.add(new Employee(3, "王五", 22, 3200));
    }
    /**
     * 用for循环遍历打印所以的工人信息
     */
    public void show() {
        System.out.println("插入一个新的员工信息！");
        list.add(new Employee(4, "赵林", 24, 3300));


        System.out.println("for循环遍历集合！");
        System.out.println("工号\t\t姓名\t\t年龄\t\t工资");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getNameIdl() + "\t\t" + list.get(i).getName() + "\t\t" +
                    list.get(i).getAge() + "\t\t" + list.get(i).getYSd());

        }

        System.out.println("删除王五的信息！");
        list.remove(2);
        for (int i = 0; i < list.size(); i++) {
//            System.out.println(list.get(i).getNameIdl() + "\t\t" + list.get(i).getName() + "\t\t" +
//            list.get(i).getAge() + "\t\t" + list.get(i).getYSd());
            System.out.println(list.get(i).toString());
        }

        /**
         * 迭代器 Iterator
         */

        Iterator<Employee> employee = list.listIterator();
        while (employee.hasNext()){
            Employee employee1 =employee.next();
            employee1.work();
        }
    }
}




